-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
core: voluntary exit #648
core: voluntary exit #648
Conversation
Codecov Report
@@ Coverage Diff @@
## main #648 +/- ##
==========================================
- Coverage 55.23% 55.13% -0.11%
==========================================
Files 98 98
Lines 9477 9652 +175
==========================================
+ Hits 5235 5322 +87
- Misses 3492 3560 +68
- Partials 750 770 +20
Continue to review full report at Codecov.
|
core/types.go
Outdated
DutyProposer DutyType = 1 | ||
DutyAttester DutyType = 2 | ||
DutyRandao DutyType = 3 | ||
DutyVoluntaryExit DutyType = 4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would propose we rename this to DutyExit
, since there is only this type of exit duty, there are no non-voluntary or any other type of exit duty. This also aligns with the other duties above, which is just DutyProposer
and DutyRandao
instead of more verbose redundant versions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't fell comfortable with this, there will be other Exits in the code, could we ask for feedback to @OisinKyne @dB2510 @xenowits ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
core/bcast/bcast.go
Outdated
ve := new(eth2p0.SignedVoluntaryExit) | ||
err := json.Unmarshal(aggData.Data, ve) | ||
if err != nil { | ||
return errors.Wrap(err, "json decoding voluntary exit") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please follow above pattern of extracting this to core.DecodeExitAggSignedData
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
core/bcast/bcast.go
Outdated
if err == nil { | ||
log.Info(ctx, "Voluntary exit successfully submitted to beacon node", | ||
z.U64("epoch", uint64(ve.Message.Epoch)), | ||
z.U64("validatorIndex", uint64(ve.Message.ValidatorIndex)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use snake case for json logging fields (see guidelines)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would also add the pubkey here: z.Any("pubkey", pubkey)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
core/bcast/bcast_test.go
Outdated
ve := ð2p0.SignedVoluntaryExit{ | ||
Message: ð2p0.VoluntaryExit{ | ||
Epoch: 10, | ||
ValidatorIndex: 10, | ||
}, | ||
Signature: testutil.RandomEth2Signature(), | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you could extract this as testutil.RandomSignedVoluntaryExit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think it is too small to extract plus it would be used only here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
core/bcast/bcast_test.go
Outdated
aggDataData, err := json.Marshal(ve) | ||
require.NoError(t, err) | ||
|
||
aggData := core.AggSignedData{ | ||
Data: aggDataData, | ||
Signature: core.SigFromETH2(ve.Signature), | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extract this to core.EncodeExitAggSignedData
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
core/validatorapi/validatorapi.go
Outdated
return errors.New("cannot find validator", z.U64("ValidatorIndex", uint64(ve.Message.ValidatorIndex))) | ||
} | ||
|
||
pubKeyBytes, err := vs[ve.Message.ValidatorIndex].PubKey(ctx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will panic if the map contains a different index.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can rename variable to eth2Pubkey
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done both things
core/validatorapi/validatorapi.go
Outdated
data, err := json.Marshal(ve) | ||
if err != nil { | ||
return nil | ||
} | ||
|
||
parSigDate := core.ParSignedData{ | ||
Data: data, | ||
Signature: core.SigFromETH2(ve.Signature), | ||
ShareIdx: c.shareIdx, | ||
} | ||
|
||
parsigSet := core.ParSignedDataSet{ | ||
pubKey: parSigDate, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can use core.Encode...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
core/validatorapi/validatorapi.go
Outdated
duty := core.Duty{ | ||
Type: core.DutyVoluntaryExit, | ||
Slot: math.MaxInt64, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would use slot 0, since a zero value in golang often means "unset" and slot 0 isn't a valid eth2 slot.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or actually, we should probably convert the epoch into a slot (1st slot in the epoch) and use that. Just incase multiple exits are requested with different epochs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, I do it but I will put a reference that it was your idea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
eth2util/signing/signing.go
Outdated
@@ -33,7 +33,7 @@ const ( | |||
DomainBeaconAttester DomainName = "DOMAIN_BEACON_ATTESTER" | |||
DomainRandao DomainName = "DOMAIN_RANDAO" | |||
// DomainDeposit DomainName = "DOMAIN_DEPOSIT" | |||
// DomainVoluntaryExit DomainName = "DOMAIN_VOLUNTARY_EXIT" | |||
DomainVoluntaryExit DomainName = "DOMAIN_VOLUNTARY_EXIT" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can move this up to just below DomainRandao
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
core/validatorapi/validatorapi.go
Outdated
if err != nil { | ||
return err | ||
} | ||
if len(vs) != 1 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can do else if
since it is part of the error handling/validator of the above call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have changed this code, so this `if len' is not anymore
Not sure the description of the PR is correct. This doesn't have anything to do with offline validators? This is just adding support for voluntary exit data...? |
core/bcast/bcast.go
Outdated
@@ -72,6 +77,7 @@ func (b Broadcaster) Broadcast(ctx context.Context, duty core.Duty, | |||
z.U64("slot", uint64(att.Data.Slot)), | |||
z.U64("target_epoch", uint64(att.Data.Target.Epoch)), | |||
z.Hex("agg_bits", att.AggregationBits.Bytes()), | |||
z.Any("pubkey", pubkey.String()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can remove .String()
since z.Any
does that automatically
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
core/validatorapi/validatorapi.go
Outdated
// By instructions of @corverroos I am putting an epoch into a field called Slot | ||
// https://github.com/ObolNetwork/charon/pull/648#discussion_r886724647 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment doesn't seem very professional
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am happy to remove it, and you add the code in a commit under your name.
If this is a bad decision, that you or the company should be ashamed of, please let me know why we are taking it, when there are better alternatives.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so, do you want me to remove it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
core/validatorapi/validatorapi.go
Outdated
Type: core.DutyVoluntaryExit, | ||
// By instructions of @corverroos I am putting an epoch into a field called Slot | ||
// https://github.com/ObolNetwork/charon/pull/648#discussion_r886724647 | ||
Slot: int64(ve.Message.Epoch), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant converting the epoch into the first slot of the epoch. not just using the epoch itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that is not what you said, do you want to change it again?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes please.
Note I said:
or actually, we should probably convert the epoch into a slot (1st slot in the epoch) and use that. Just incase multiple exits are requested with different epochs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok so I revert it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@corverroos you are editing comments to change what you said
testutil/random.go
Outdated
} | ||
} | ||
|
||
func RandomSignedVoluntaryExit(t *testing.T) *eth2p0.SignedVoluntaryExit { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
t
not required since not used
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
testutil/random.go
Outdated
@@ -376,3 +376,24 @@ func RandomUnsignedDataSet(t *testing.T) core.UnsignedDataSet { | |||
RandomCorePubKey(t): unsigned, | |||
} | |||
} | |||
|
|||
func RandomVoluntaryExit(t *testing.T) *eth2p0.VoluntaryExit { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
t
not required since not used
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it isn't used, so you do not need to include it, some random things require it, others don't.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
t.Helper() | ||
|
||
return ð2p0.SignedVoluntaryExit{ | ||
Message: ð2p0.VoluntaryExit{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can replace with RandomVoluntaryExit()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
core/encode.go
Outdated
@@ -102,6 +102,22 @@ func EncodeAttestationParSignedData(att *eth2p0.Attestation, shareIdx int) (ParS | |||
}, nil | |||
} | |||
|
|||
// EncodeVoluntaryExitParSignedData encodes to json to pass between Go components losing typing, | |||
// returns a ParSignedData that contains json. | |||
// WARNING: using this method makes you lose Golang type safety features. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please remove unprofessional comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is unprofessional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Putting personal style disagreements into the code as comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not a personal style, this is a statement of fact, that other contributors should be aware of.
If you think this decision is shameful, we should decide about why we are doing it this way, when there are easier ways.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can find in Open Source software this type of comments very often, that using a method is dangerous for example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I disagree with putting personal style disagreements into the code as comments.
| Not sure the description of the PR is correct. This doesn't have anything to do with offline validators? This is just adding support for voluntary exit data...? The PR description is from the ticket from @OisinKyne if you have a better description please change it. |
@corverroos if you want to put something else in the Slot of the duty, please push it as a commit to this branch, I am confused about what you want there |
@corverroos I have remove the WARNING comment and changed VoluntaryExit to Exit. The epoch thing I don't understand please add a commit to the branch before merging. Cheers! |
Adds support for voluntary exits via a new
DutyExit
.category: feature
ticket: #553